cc.Class({
  extends: cc.Component,
  editor: false,
  properties: {
    offset: cc.v2(0, 0),
    duration: 3
  },
  onLoad: function () {
    this.rc = this.node.getComponent(cc.RenderComponent);
  },
  start: function () {
    this.code = 1;
    this.addtime = 0;
    this.uv_delta_x = 1;
    this.uv_delta_y = 1;
    this.offset_x = this.uv_delta_x / this.duration / cc.game.getFrameRate();
    this.offset_y = this.uv_delta_y / this.duration / cc.game.getFrameRate();
    this.offset_x1 = this.offset_x;
    this.offset_y1 = -this.offset_y;
  },
  onEnable: function () {},
  switchCode: function () {
    switch (this.code) {
      case 1:
      case 2:
        this.code = 3;
        break;
      case 3:
        this.code = 4;
        break;
      case 4:
        this.code = 1;
    }
    switch (this.code) {
      case 1:
        this.offset_x1 = this.offset_x;
        this.offset_y1 = this.offset_y;
        break;
      case 2:
        this.offset_x1 = -this.offset_x;
        this.offset_y1 = this.offset_y;
        break;
      case 3:
        this.offset_x1 = -this.offset_x;
        this.offset_y1 = -this.offset_y;
        break;
      case 4:
        this.offset_x1 = this.offset_x;
        this.offset_y1 = -this.offset_y;
    }
  },
  update: function (e) {
    this.addtime += e;
    this.addtime > 10 && (this.addtime = 0);
    var t = this.offset.x + this.offset_x1;
    t >= this.uv_delta_x && (t += this.uv_delta_x);
    var o = this.offset.y + this.offset_y1;
    o >= this.uv_delta_y && (o += this.uv_delta_y);
    this.offset = cc.v2(t, o);
    this.rc.getMaterial(0).setProperty("uv_offset", this.offset);
  }
});